﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Data.SqlClient;
using WAD.Model;

namespace WAD.DAL
{
    public class DaoLogcat : DAO
    {
        /// <summary>
        /// 添加一条日志
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public static bool Add(MLogcat m)
        {
            return Add(m.type, m.content);
        }

        public static bool Add(String type, String content)
        {
            String sql = "insert into logcat(type,content,date)values(@type,@content,getdate())";
            Database db = GetDatabase();
            DbCommand cmd = db.GetSqlStringCommand(sql);
            db.AddInParameter(cmd, "@type", DbType.String, type);
            db.AddInParameter(cmd, "@content", DbType.String, content);
            return db.ExecuteNonQuery(cmd) > 0;
        }

        public static List<Dictionary<string, object>> testList()
        {
            String sql = "select top 100 * from new_list";

            return GetList(sql);
        }

        public static DataTable testTable()
        {
            String sql = "select top 100 * from new_list";
            Database db = GetDatabase();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            DataSet ds = db.ExecuteDataSet(cmd);
            DataTable table = ds.Tables[0];
            return table;
        }

    }
}
